//Source file: D:\\test\\com\\ce\\pms\\house\\model\\ProjectDomain.java

package com.ce.pms.house.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.Where;

import com.ce.pms.common.model.SysInfo;
import com.ce.webframework.exception.BizLayerException;
import com.sitechasia.webx.core.model.IDomainObject;

/**
 * 实体名称:期 关系表名称:HM_PROJECT 备注: developers,designCorps
 * buildCorps,surveillants几个集合手动在relationOrgs赋值后初始化.
 */
@Entity
@Table(name = "HM_PROJECT")
public class ProjectDomain implements IDomainObject{

	/**
	 * 建设期主键
	 */
	@Id
	@GeneratedValue
	@Column(name = "PROJECT_ID")
	private Long keyword;

	/**
	 * 楼盘 检索策略:lazy=true
	 */
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "AREA_ID", nullable = false)
	private AreaDomain area;

	/**
	 * 名称
	 */
	@Column(name = "NAME", nullable = false, length = 100)
	private String name;

	/**
	 * 配套设施
	 * 检索策略:lazy=false
	 * 级联配置:cascade=all-delete-orphan
	 */
	@OneToOne(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
	@org.hibernate.annotations.Cascade({
		org.hibernate.annotations.CascadeType.DELETE_ORPHAN
	})
	@JoinColumn(name="LAYOUT_ID")
	 private Layout layout;

	 /**
	 * 开发商
	 */
	 @ManyToMany(cascade={CascadeType.ALL})
//	 @Where(clause="SYS_REF_ID = 65")
	 @Where(clause="SYS_REF_ID = (SELECT ALIAS.SYS_REF_ID FROM SYS_REF_CODE AS ALIAS WHERE ALIAS.SYS_REF_CODE = 'CS_CO_WORKER_TYPE' AND ALIAS.SYS_REF_VALUE='004')")
	 @org.hibernate.annotations.Cascade({
		 org.hibernate.annotations.CascadeType.SAVE_UPDATE
//		 org.hibernate.annotations.CascadeType.DELETE_ORPHAN
	})
	 @JoinTable(name="CS_CO_WORKER_R_PROJECT",
			 joinColumns={@JoinColumn(name="PROJECT_ID")},
			 inverseJoinColumns={@JoinColumn(name="CO_WORKER_ID")})
	 private Set<CoWorkerDomain> developers=new HashSet<CoWorkerDomain>();

	/**
	 * 设计单位
	 */
	 @ManyToMany
	 @Where(clause="SYS_REF_ID = 66")
	 @org.hibernate.annotations.Cascade({
		 org.hibernate.annotations.CascadeType.SAVE_UPDATE
//		org.hibernate.annotations.CascadeType.DELETE_ORPHAN
	})
	 @JoinTable(name="CS_CO_WORKER_R_PROJECT",
			 joinColumns={@JoinColumn(name="PROJECT_ID")},
			 inverseJoinColumns={@JoinColumn(name="CO_WORKER_ID")})
	 private Set<CoWorkerDomain> designCorps=new HashSet<CoWorkerDomain>();

	 /**
	 * 施工单位
	 */
	 @ManyToMany
	 @Where(clause="SYS_REF_ID = 67")
	 @org.hibernate.annotations.Cascade({
		 org.hibernate.annotations.CascadeType.SAVE_UPDATE
//		org.hibernate.annotations.CascadeType.DELETE_ORPHAN
	})
	 @JoinTable(name="CS_CO_WORKER_R_PROJECT",
			 joinColumns={@JoinColumn(name="PROJECT_ID")},
			 inverseJoinColumns={@JoinColumn(name="CO_WORKER_ID")})
	 private Set<CoWorkerDomain> buildCorps=new HashSet<CoWorkerDomain>();

	 /**
	 * 监理单位
	 */
	 @ManyToMany
	 @Where(clause="SYS_REF_ID = 68")
	 @org.hibernate.annotations.Cascade({
		 org.hibernate.annotations.CascadeType.SAVE_UPDATE
//		org.hibernate.annotations.CascadeType.DELETE_ORPHAN
	})
	 @JoinTable(name="CS_CO_WORKER_R_PROJECT",
			 joinColumns={@JoinColumn(name="PROJECT_ID")},
			 inverseJoinColumns={@JoinColumn(name="CO_WORKER_ID")})
	 private Set<CoWorkerDomain> surveillants = new HashSet<CoWorkerDomain>();

	 /**
	 * 配套设施
	 * 检索策略:lazy=false
	 * 级联配置:cascade=all-delete-orphan
	 */
	 @OneToMany(mappedBy="project")
	 @org.hibernate.annotations.Cascade(
			 {
				 org.hibernate.annotations.CascadeType.SAVE_UPDATE,
				 org.hibernate.annotations.CascadeType.DELETE,
				 org.hibernate.annotations.CascadeType.DELETE_ORPHAN
			 })
	 private Set<Environment> environments = new HashSet<Environment>();

//	 /**
//	 * 协作伙伴
//	 * 检索策略:lazy=false
//	 */
//	 @ManyToMany
//	 @JoinTable(name="CS_CO_WORKER_R_PROJECT",
//			 joinColumns={@JoinColumn(name="PROJECT_ID")},
//			 inverseJoinColumns={@JoinColumn(name="CO_WORKER_ID")})
//	 private Set<CoWorkerDomain> relationOrgs;
	@Embedded
	private SysInfo sysInfo;

	/**
	 * @roseuid 484F3FA70290
	 */
	public ProjectDomain() {

	}

	/**
	 * mini constructor
	 * @param area 楼盘
	 * @param name 期名
	 * @param sysInfo 系统信息
	 */
	public ProjectDomain(AreaDomain area, String name, SysInfo sysInfo) {
		super();
		this.area = area;
		this.name = name;
		this.sysInfo = sysInfo;
	}


	/**
	 * 方法描述: 检查不允许空字段.
	 * @author 胡煦
	 * Create on:2008-7-3
	 * @param o
	 * @return
	 * @roseuid 48479CFD02CE
	 * Edit on:
	 * 修改原因：
	 */
	public void checkFields(ProjectDomain o) {
		if(o.getArea() == null ||o.getName() == null ||
				o.getSysInfo() == null  ){
		}throw new BizLayerException("必填项不能为空");
	}
	/**************************************************
	 * Accessors and Modifiers
	 **************************************************/
	public AreaDomain getArea() {
		return area;
	}

	public void setArea(AreaDomain area) {
		this.area = area;
	}

	public Long getKeyword() {
		return keyword;
	}

	public void setKeyword(Long keyword) {
		this.keyword = keyword;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public SysInfo getSysInfo() {
		return sysInfo;
	}

	public void setSysInfo(SysInfo sysInfo) {
		this.sysInfo = sysInfo;
	}

	public Set<CoWorkerDomain> getBuildCorps() {
		return buildCorps;
	}

	public void setBuildCorps(Set<CoWorkerDomain> buildCorps) {
		this.buildCorps = buildCorps;
	}

	public Set<CoWorkerDomain> getDesignCorps() {
		return designCorps;
	}

	public void setDesignCorps(Set<CoWorkerDomain> designCorps) {
		this.designCorps = designCorps;
	}

	public Set<CoWorkerDomain> getDevelopers() {
		return developers;
	}

	public void setDevelopers(Set<CoWorkerDomain> developers) {
		this.developers = developers;
	}

	public Set<Environment> getEnvironments() {
		return environments;
	}

	public void setEnvironments(Set<Environment> environments) {
		this.environments = environments;
	}

	public Layout getLayout() {
		return layout;
	}

	public void setLayout(Layout layout) {
		this.layout = layout;
	}

//	public Set<CoWorkerDomain> getRelationOrgs() {
//		return relationOrgs;
//	}
//
//	public void setRelationOrgs(Set<CoWorkerDomain> relationOrgs) {
//		this.relationOrgs = relationOrgs;
//	}

	public Set<CoWorkerDomain> getSurveillants() {
		return surveillants;
	}

	public void setSurveillants(Set<CoWorkerDomain> surveillants) {
		this.surveillants = surveillants;
	}




}
